home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / lists / mint / l_1199 / 1090 < prev    next >
Encoding:
Internet Message Format  |  1994-08-27  |  3.4 KB

  1. Subject: Re: tosfs, faster hash function...
  2. Date: Wed, 23 Feb 94 23:16:44 CET
  3. From: Juergen Lock <nox@jelal.north.de>
  4. In-Reply-To: <9402221314.AA11542@math.uni-muenster.de>; from "Julian Reschke" at Feb 22, 94 2:14 pm
  5. Message-Id: <9402232216.AA00510@jelal.north.de>
  6.  
  7. Julian Reschke writes:
  8.  
  9. > Re inodes: everybofy with large TOS filesystems should verify that
  10. > the (computed) inodes indeed are unique (as I said: it's highly
  11. > probale, but it can't be guaranteed). If you have gnu-find or my
  12. > find.ttp (mupftl02.tos, ftp.uni-muenster.de, pub/atari/Gemini),
  13. > you can try the following script:
  14. > find \ -printf "%i\n" > inodes.all
  15. > sort inodes.all > inodes.tot
  16. > uniq inodes.tot > inodes.uni
  17. > wc -l inodes.tot inodes.uni
  18.  
  19.  or diff -u ...
  20.  
  21. > rm inodes.tot inodes.uni inodes.all
  22.  ..but thats not why i followup :)
  23.  
  24. >+ 
  25. >+ #define UPDC32(octet, crc) (((crc) << 8) ^ crctab[((crc) >> 24) ^ (octet)])
  26.  
  27.  hmm shifts are slow on 68000...  here is one that should be a bit faster,
  28. from dbz (cnews):
  29.  
  30. /*
  31.  * This is a simplified version of the pathalias hashing function.
  32.  * Thanks to Steve Belovin and Peter Honeyman
  33.  *
  34.  * hash a string into a long int.  31 bit crc (from andrew appel).
  35.  * the crc table is computed at run time by crcinit() -- we could
  36.  * precompute, but it takes 1 clock tick on a 750.
  37.  *
  38.  * This fast table calculation works only if POLY is a prime polynomial
  39.  * in the field of integers modulo 2.  Since the coefficients of a
  40.  * 32-bit polynomial won't fit in a 32-bit word, the high-order bit is
  41.  * implicit.  IT MUST ALSO BE THE CASE that the coefficients of orders
  42.  * 31 down to 25 are zero.  Happily, we have candidates, from
  43.  * E. J.  Watson, "Primitive Polynomials (Mod 2)", Math. Comp. 16 (1962):
  44.  *    x^32 + x^7 + x^5 + x^3 + x^2 + x^1 + x^0
  45.  *    x^31 + x^3 + x^0
  46.  *
  47.  * We reverse the bits to get:
  48.  *    111101010000000000000000000000001 but drop the last 1
  49.  *         f   5   0   0   0   0   0   0
  50.  *    010010000000000000000000000000001 ditto, for 31-bit crc
  51.  *       4   8   0   0   0   0   0   0
  52.  */
  53.  
  54. #define POLY 0x48000000L    /* 31-bit polynomial (avoids sign problems) */
  55.  
  56. static long CrcTable[128];
  57.  
  58. /*
  59.  - crcinit - initialize tables for hash function
  60.  */
  61. static void
  62. crcinit()
  63. {
  64.     register int i, j;
  65.     register long sum;
  66.  
  67.     for (i = 0; i < 128; ++i) {
  68.         sum = 0L;
  69.         for (j = 7 - 1; j >= 0; --j)
  70.             if (i & (1 << j))
  71.                 sum ^= POLY >> j;
  72.         CrcTable[i] = sum;
  73.     }
  74.     DEBUG(("crcinit: done\n"));
  75. }
  76.  
  77. /*
  78.  - hash - Honeyman's nice hashing function
  79.  */
  80. static long
  81. hash(name, size)
  82. register char *name;
  83. register int size;
  84. {
  85.     register long sum = 0L;
  86.  
  87.     while (size--) {
  88.         sum = (sum >> 7) ^ CrcTable[(sum ^ (*name++)) & 0x7f];
  89.     }
  90.     DEBUG(("hash: returns (%ld)\n", sum));
  91.     return(sum);
  92. }
  93.  
  94.  i have not done tests which one is better for filenames but there should
  95. be no difference.
  96.  
  97. >+ 
  98. >+ static unsigned long
  99. >+ filename_crc (const char *filename)
  100. >+ {
  101. >+     unsigned long s = 0;
  102. >+     unsigned int n = 0;
  103. >+     
  104. >+     /* skip x: */
  105. >+     filename += 2;
  106. >+     
  107. >+     while (*filename) {
  108. >+         s = UPDC32 (*filename++, s);
  109. >+         n++;
  110. >+     }
  111. >+ 
  112. >+     while (n != 0) {
  113. >+         s = UPDC32 (n & 0377, s);
  114. >+         n >>= 8;
  115. >+     }
  116. >+     
  117. >+     return s;
  118. >+ }
  119. >+ 
  120. >+ #endif
  121.  
  122.  does the second loop improve results?
  123.  
  124.  just a thought...
  125.     Juergen
  126.  
  127. PS: there is a problem too with using start clusters: 0 byte files...
  128. -- 
  129. J"urgen Lock / nox@jelal.north.de / UUCP: ..!uunet!unido!uniol!jelal!nox
  130.                                 ...ohne Gewehr
  131. PGP public key fingerprint =  8A 18 58 54 03 7B FC 12  1F 8B 63 C7 19 27 CF DA 
  132.